*** REPLICATION TOOLKIT ***

* AUTHORS: CIMINELLI DUVAL FURCERI 

* ARTICLE: EMPLOYMENT PROTECTION DEREGULATION AND LABOR SHARES IN ADVANCED ECONOMIES 

* JOURNAL: REVIEW OF ECONOMICS AND STATISTICS

* OUTPUT: FIGURE E5 (ONLINE APPENDIX)

***************************

cd ""

use "DTA files/Dataset", clear

global se90 = 1.6

**************** TIME TRENDS IN LABOR SHARE BY COUNTRY *******************

gen a = 100*lab/va

* Create matrix where to store the results
egen id1 = group(ifscode)
sum id1
local max = r(max)
mat trends = J(`max',6,.)

* Create linear time trend variable 
egen trend = group(year)

* Perform regression and save relevant results
forvalues i=1/`max' {
quietly xtreg a trend if id1==`i', fe
matrix results = r(table)
matrix trends[`i',1]=results[1,1]
matrix trends[`i',2]=results[2,1]
matrix trends[`i',3]=results[4,1]
}

* Assign country names to name variable
matrix rownames trends = UnitedStates UnitedKingdom Austria Belgium Denmark France Germany Italy Luxembourg Netherlands Sweden Canada Japan Finland Greece Ireland Portugal Spain Australia Korea CzechRepublic Slovakia
matrix trans_trends = trends'
forvalues j=1/2 {
matrix rowtest`j' = trans_trends["c`j'", 1...]
}
local names : colnames rowtest1
local n_names : word count `names'
gen var_colnames = ""
forval i=1/`n_names' {
local this_name = "`:word `i' of `names''"
replace var_colnames = "`this_name'" if _n == `i'
}

* Tranpose matrix rowtest1 and 2
forvalues j=1/2 {
matrix trans_rowtest`j' = rowtest`j''
}
* Create new variable tran_rowtest from the transpose of matrix rowtest (In this matrix the linear trends are stored)
svmat trans_rowtest1, name(tot_beta)
svmat trans_rowtest2, name(tot_se)

* Graph

* Prepare variables
gen tot_ci_p = tot_beta1+$se90*tot_se1
gen tot_ci_n = tot_beta1-$se90*tot_se1

* Names for legend
sort tot_beta1
g tot_order=_n
replace tot_order = . if tot_beta1==.

sum tot_order
local max = r(max)
forvalues j=1/`max' {
local n`j' = var_colnames[`j']
}

* Graph
eclplot tot_beta tot_ci_p tot_ci_n tot_order, yline(0, lcolor(black)) xtitle("") ytitle("") graphregion(color(white)) estopts(barwidth(0.75) bcolor(blue) blcolor(black))  ciopts(blcolor(black)) eplottype(bar)  ////
xlabel(1 "`n1'" 2 "`n2'" 3 "`n3'" 4 "`n4'" 5 "`n5'" 6 "`n6'" 7 "`n7'" 8 "`n8'" 9 "`n9'" 10 "`n10'" 11 "`n11'"  12 "`n12'" 13 "`n13'" 14 "`n14'" 15 "`n15'" 16 "`n16'" 17 "`n17'" 18 "`n18'" 19 "`n19'" 20 "`n20'" 21 "`n21'" 22 "`n22'" , labsize(small) angle(60) labgap(small) noticks)
graph export "Figures/E5.png", replace
